package pl.put.miasi.volleyball;

import pl.put.miasi.agents.GUI;
import pl.put.miasi.agents.PlayerAgent;
import pl.put.miasi.agents.Team;


public class Implementation extends Volleyball {
	

	
	
	public Implementation(Main _parent) {
		super(_parent);
		gui = new GUI(this);
		blueTeam = new Team(1);
		yellowTeam = new Team(2);
		playerAgent = new PlayerAgent[6];
		for (int i = 0; i < 3; i++) {
			this.playerAgent[i] = new PlayerAgent(i, blueTeam, gui);
			blueTeam.registerPlayer(playerAgent[i], null);
		}
		for (int i = 3; i < 6; i++) {
			this.playerAgent[i] = new PlayerAgent(i, yellowTeam, gui);
			yellowTeam.registerPlayer(playerAgent[i], null);
		}
	}

	@Override
	public synchronized void create() {
		if (firstTime) {
			setCamera(Settings.CAMERA_X, Settings.CAMERA_Y,
					Settings.CS);
			firstTime = false;
		}
		/********/
		//Create walls
		b2Walls = new B2Walls(this);
		b2Walls.initialize();
		
		//Create net
		this.netEndingPart = b2Walls.getNetEndingPart();
		b2Net = new B2Net(this);
		b2Net.initialize();
		
		//Create ball
		b2Ball = new B2Ball(this);
		b2Ball.initialize();
		this.ballBody = b2Ball.getBallBody();
		
		//Create players
		b2Player = new B2Player[6];
		for (int i=0; i<3; i++)
		{
			b2Player[i] = new B2Player(volleyball, true, Settings.PLAYERS_INITIAL[i]);
			b2Player[i].initialize();
		}
		for (int i=3; i<6; i++)
		{
			b2Player[i] = new B2Player(volleyball, false, Settings.PLAYERS_INITIAL[i]);
			b2Player[i].initialize();
		}
		
		for (int i = 0; i < 6; i++) {
			Thread thread = new Thread(this.playerAgent[i]);
			thread.start();
		}
		/********/
	}	
}
